package com.tyc.mb.test.demo6;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Bean;

@Slf4j
public class MyBean implements BeanNameAware, ApplicationContextAware, InitializingBean {
    @Autowired
    private ApplicationContext applicationContext;

    @Override
    public void setBeanName(String name) {
        log.info("MyBean类的bean名称为：{}",name);
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        log.info("当前bena初始化");
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
//        this.applicationContext = applicationContext;
        log.info("当前容器为：{}",applicationContext);
    }

    @Bean(initMethod = "",destroyMethod = "")
    public ApplicationContext getApplicationContext() {
        return applicationContext;
    }
}
